package com.rslai.base.tool.servertest.database.mysql;

import javax.sql.DataSource;
import org.dbunit.AbstractDatabaseTester;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.ext.mysql.MySqlConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MySqlJdbcDataBaseTester extends AbstractDatabaseTester
{
    private static final Logger logger = LoggerFactory.getLogger(MySqlJdbcDataBaseTester.class);
    private DataSource dataSource;

    public MySqlJdbcDataBaseTester(DataSource dataSource)
    {
        this.dataSource = dataSource;
    }

    public IDatabaseConnection getConnection() throws Exception {
        logger.debug("getConnection() - start");
        MySqlConnection connection = new MySqlConnection(this.dataSource.getConnection(), getSchema());
        connection.getConfig().setProperty("http://www.dbunit.org/properties/datatypeFactory", new MysqlDataTypeFactory());
        connection.getConfig().setProperty("http://www.dbunit.org/properties/escapePattern", "`");
        return connection;
    }
}
